package com.example.textroom.data.repository.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.textroom.bead.Word;
import com.example.textroom.data.repository.WordRepository;

import java.util.List;

public class WordViewModel extends AndroidViewModel {
    private final WordRepository wordRepository;
    public WordViewModel(@NonNull Application application) {
        super(application);
        // 将 Database，Dao，ThreadPool 相关的操作，进一步从 ViewModel 移到 Repository 中去了。
        wordRepository = new WordRepository(application);
    }

    public LiveData<List<Word>> getAllWordsLive() {
        return wordRepository.getAllWordsLive();
    }

    void insertWords(Word... words){
        // executorService.submit(() -> wordDao.insertWords(words));
        wordRepository.insertWords(words);
    }

    void deleteWords(Word... words){
        // executorService.submit(() -> wordDao.deleteWords(words));
        wordRepository.deleteWords(words);
    }
    void updateWords(Word... words){
        // executorService.submit(() -> wordDao.updateWords(words));
        wordRepository.updateWords(words);
    }
    void deleteAllWords(){
        wordRepository.deleteAllWords();
    }

}
